package servlet.shopping;

import bean.Result;
import com.google.gson.Gson;
import dao.ProductDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ShoppingRecommendServlet", value = "/ShoppingRecommendServlet.s")
public class ShoppingRecommendServlet extends HttpServlet {
    private ProductDao dao = new ProductDao();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String recommend = request.getParameter("recommend");
        final String proid = request.getParameter("proid");
        final int count = dao.modifyRecommend(proid, recommend);
        Result result ;
        if (count == 0){
            result = new Result(1,"修改失败",null);

        }else{
            result = new Result(1,"修改成功",null);
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }
}
